import { defineStore } from 'pinia'
import { AxiosError } from 'axios'

export const useAppStore = defineStore('application', () => {

  function catchHttpError(res) {
    if (res instanceof AxiosError) {
      const { response } = res

      if (!response?.data?.result) {
        msg.error(response.data.msg)
      } else {
        msg.error(res.message)
      }
    }
    return res
  }

  return { catchHttpError }
})
